package leetcode.editor.cn.q1_300.q50;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author qidi
 * @date 2021-12-20 09:37:09
 */
class Q0077_Combinations {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        List<List<Integer>> res = new ArrayList<>();
        LinkedList<Integer> inner = new LinkedList<>();

        public List<List<Integer>> combine(int n, int k) {
            process(n, k, 1);

            return res;
        }

        private void process(int n, int k, int curNum) {
            if (inner.size() == k) {
                res.add(new ArrayList<>(inner));
                return;
            }

            for (int i = curNum; i <= n - (k - inner.size()) + 1; i++) {
                inner.add(i);
                process(n, k, i + 1);
                inner.removeLast();
            }
        }
    }
    //leetcode submit region end(Prohibit modification and deletion)


    public static void main(String[] args) {
        Solution solution = new Q0077_Combinations().new Solution();
        System.out.println(solution.combine(4, 2));
        System.out.println(solution.combine(1, 1));
        System.out.println(solution.combine(3, 3));
        System.out.println(solution.combine(20, 5));
    }
}